<template>
	<view class="container">
		<!-- 顶部标题 -->
		<view class="header">
			<text class="header-title">我的钱包</text>
		</view>

		<!-- 余额信息卡片 -->
		<view class="balance-card">
			<view class="balance-info">
				<text class="label">{{moneyType+"："}}</text>
				<text class="amount">{{ balance }}</text>
			</view>
		</view>

		<!-- 明细选项卡 -->
		<view class="details-tab">
			<text :class="{'active': activeTab === 'expenditure'}" @click="switchTab('expenditure')">支出明细</text>
			<text :class="{'active': activeTab === 'income'}" @click="switchTab('income')">收入明细</text>
		</view>

		<!-- 明细内容 -->
		<view class="details-content">
			<view v-if="activeTab === 'expenditure'">
				<text v-if="expenditureDetails.length === 0" class="no-data">暂无支出数据</text>
				<view v-for="(item, index) in expenditureDetails" :key="index" class="detail-item">
					<text>{{ item.date }} {{ item.amount }}元</text>
					<text>{{ item.description }}</text>
				</view>
			</view>
			<view v-if="activeTab === 'income'">
				<text v-if="incomeDetails.length === 0" class="no-data">暂无收入数据</text>
				<view v-for="(item, index) in incomeDetails" :key="index" class="detail-item">
					<text>{{ item.date }} {{ item.amount }}元</text>
					<text>{{ item.description }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		TWallet,
	} from '@/api/user.js';
	export default {
		data() {
			return {
				activeTab: 'expenditure', // 当前选中的明细标签
				balance: '', // 总余额
				moneyType:'',//币种
				expenditureDetails: [], // 支出明细数据
				incomeDetails: [] // 收入明细数据
			}
		},
		methods: {
			getTWalletlist() {
				TWallet({
					userId: this.$cookies.get("id")
				}).then(res => {
					if (res.message == "success") {
						this.balance = res.data.balance;
						this.moneyType=res.data.moneyType;
					} else {
						uni.showToast({
							type: 'error',
							icon: 'none',
							title: '获取失败'
						});
					}
				})
			},
			// 切换选中的明细标签
			switchTab(tab) {
				this.activeTab = tab;
			},
		},
		onLoad() {
			this.getTWalletlist()
		}
	}
</script>

<style>
	.container {
		background-color: #f5f5f5;
		min-height: 100vh;
		padding: 16px;
	}

	/* 顶部标题 */
	.header {
		display: flex;
		align-items: center;
		padding-bottom: 16px;
		position: relative;
	}

	.header-title {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
	}

	/* 余额信息卡片 */
	.balance-card {
		background: linear-gradient(135deg, #2ac2d2, #ade0a8);
		border-radius: 8px;
		padding: 20px;
		color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.balance-info {
		flex: 1;
	}

	.label {
		font-size: 14px;
	}

	.amount {
		font-size: 32px;
		font-weight: bold;
		margin-top: 5px;
	}

	.frozen-balance {
		font-size: 12px;
		margin-top: 10px;
		color: rgba(255, 255, 255, 0.8);
	}

	/* 明细选项卡 */
	.details-tab {
		display: flex;
		justify-content: center;
		background-color: #fff;
		border-bottom: 1px solid #eee;
		margin-top: 16px;
	}

	.details-tab text {
		padding: 12px 20px;
		font-size: 16px;
		color: #333;
		cursor: pointer;
	}

	.details-tab .active {
		color: #FF9800;
		border-bottom: 2px solid #FF9800;
	}

	/* 明细内容 */
	.details-content {
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #fff;
		margin-top: 10px;
	}

	.detail-item {
		padding: 10px 20px;
		border-bottom: 1px solid #eee;
		width: 100%;
	}

	.no-data {
		color: #999;
		text-align: center;
	}
</style>